use anyhow::Result;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
pub struct AddLicenseResult {
    #[serde(rename = "Success")]
    pub success: bool,
    #[serde(rename = "Message")]
    pub message: String,
}

/// 尝试通过AppID领取免费游戏
pub async fn add_license_by_app(client: &reqwest::Client, appid: &str) -> Result<AddLicenseResult> {
    let url = format!(
        "{}/RequestFreeAppLicense?appIDs={}",
        crate::consts::ASF_IPC_URL,
        appid
    );
    let response = client.get(&url).send().await?;
    let result: AddLicenseResult = response.json().await?;
    Ok(result)
}

/// 尝试通过SubID领取免费游戏
pub async fn add_license_by_sub(client: &reqwest::Client, subid: &str) -> Result<AddLicenseResult> {
    let url = format!(
        "{}/RequestFreeSubLicense?subID={}",
        crate::consts::ASF_IPC_URL,
        subid
    );
    let response = client.get(&url).send().await?;
    let result: AddLicenseResult = response.json().await?;
    Ok(result)
}
